package com.pfizer.XmlContentHandler;

import java.io.InputStream;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import com.pfizer.Entity.DoctorInfo;
import com.pfizer.Entity.Handout;
import com.pfizer.Entity.HandoutClass;
import com.pfizer.Entity.HospitalInfo;
import com.pfizer.Entity.PCR;
import com.pfizer.Entity.Question;
import com.pfizer.Entity.Survey;
import com.pfizer.Entity.SurveyClass;
import com.pfizer.Entity.UserInfo;
import com.pfizer.Entity.VideoClass;
import com.pfizer.Entity.pMessage;
import com.pfizer.Entity.pNews;
import com.pfizer.Entity.pVideo;
/**
 * SaxReadXml--<b>SAX文檔解析工具類</b>
 * 對於XML格式的信息，採用SAX解析工具進行解析
 * 本類封裝了所有需要解析的XML數據獲得函數
 * 
 * 
 * @author krui
 *@version 1.0 2011/11/22
 */
public class SaxReadXml {
	/**
	 * readVideo:得到解析后的數據
	 * 
	 * 此方法包含SAX解析的API，先得到一個解析器工廠的實例，然後通過這個實例得到一個解析器，
	 * 通過解析器調用方法解析（傳入參數為一個輸入流跟事先定義好的數據handler），調用的時候
	 * 只需傳入一個XML地址的文件輸入流作為參數，返回解析后得到的list數據
	 * @param inStream
	 * @return list
	 * @throws Exception
	 * 
	 * @see  javax.xml.parsers.SAXParserFactory
	 * @see  javax.xml.parsers.SAXParser
	 * @see  com.pfizer.XmlContentHandler.VideoContentHandler
	 */
	public static  List<pVideo> readVideo(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		VideoContentHandler handler = new VideoContentHandler();
		sp.parse(inStream, handler);
		return handler.getVideos();
	}
	
	public static  List<VideoClass> readVideoClass(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser();
		VideoClassContentHandler handler = new VideoClassContentHandler();
		sp.parse(inStream, handler);
		return handler.getVideoClasss();
	}
	
	public static  List<SurveyClass> readSurveyClass(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser();
		SurveyClassContentHandler handler = new SurveyClassContentHandler();
		sp.parse(inStream, handler);
		return handler.getSurveyClasss();
	}
	
	public static  List<Survey> readSurvey(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser(); 
		SurveyContentHandler handler = new SurveyContentHandler();
		sp.parse(inStream, handler);
		return handler.getSurveys();
	}
	
	public static  List<HandoutClass> readHandoutClass(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser(); 
		HandoutClassContentHandler handler = new HandoutClassContentHandler();
		sp.parse(inStream, handler);
		return handler.getHandoutClasss();
	}
	
	public static  List<Handout> readHandout(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		HandoutContentHandler handler = new HandoutContentHandler();
		sp.parse(inStream, handler);
		return handler.getHandouts();
	}
	
	public static  List<Question> readQuestion(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		QuestionContentHandler handler = new QuestionContentHandler();
		sp.parse(inStream, handler);
		return handler.getQuestions();
	}
	
	public static  List<pMessage> readMessage(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		MessageContentHandler handler = new MessageContentHandler();
		sp.parse(inStream, handler);
		return handler.getMessages();
	}
	
	public static  List<pNews> readNews(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		NewsContentHandler handler = new NewsContentHandler();
		sp.parse(inStream, handler);
		return handler.getNewss();
	}
	
	public static  List<UserInfo> readUserInfo(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		UserInfoContentHandler handler = new UserInfoContentHandler();
		sp.parse(inStream, handler);
		return handler.getUserInfos();
	}
	
	public static  List<HospitalInfo> readHospitalInfo(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		HospitalContentHandler handler = new HospitalContentHandler();
		sp.parse(inStream, handler);
		return handler.getHospitalInfos();
	}
	
	public static  List<DoctorInfo> readDoctorInfo(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		DoctorContentHandler handler = new DoctorContentHandler();
		sp.parse(inStream, handler);
		return handler.getDoctorInfos();
	}
	
	public static  List<PCR> readPCR(InputStream inStream)throws Exception {
		SAXParserFactory spf = SAXParserFactory.newInstance(); 
		SAXParser sp = spf.newSAXParser(); 
		PCRContentHandler handler = new PCRContentHandler();
		sp.parse(inStream, handler);
		return handler.getPCRs();
	}
}
